/**
 * 
 */
package com.meiwenhui.sishuwujing;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.IconPagerAdapter;
import com.viewpagerindicator.TabPageIndicator;

public class MyCenterActivity extends FragmentActivity {
	
	private static final String[] CONTENT = new String[] { "Fav", "His" };
	private static final int[] ICONS = new int[] { R.drawable.perm_group_calendar, R.drawable.perm_group_camera };

	List<Fragment> fragments = new ArrayList<Fragment>(0);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.simple_tabs);

		fragments.add(new MyFavorite());
		fragments.add(new MyHistory());

		FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager(),fragments,Arrays.asList(CONTENT));

		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		pager.setAdapter(adapter);

		TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
		indicator.setViewPager(pager);
	}

	class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter {

		private List<Fragment> fragments;
		private List<String> titles;

		public GoogleMusicAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
			super(fm);
			this.fragments = fragments;
			this.titles = titles;
		}

		@Override
		public Fragment getItem(int position) {
			return fragments.get(position);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return titles.get(position);
		}

		@Override
		public int getIconResId(int index) {
			return ICONS[index];
		}

		@Override
		public int getCount() {
			return CONTENT.length;
		}
	}
}